<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>MessageChannel实现深拷贝</title>
</head>
<body>
  <script>
    let obj1 = {
      a:'123',
      b:undefined,
      c:{
        e:'121'
      }
    }

    function deepClone (obj) {
      return new Promise((resolve, reject) => {
        const { port1, port2 } = new MessageChannel();
        port1.postMessage(obj);
        port2.onmessage = (msg) => {
          resolve(msg);
        }
      })
    }

    deepClone(obj1).then((res) => {
      console.log(res.data, res.data === obj1);
    })
  </script>
  
</body>
</html>